package mao.leetcode.others.leetcode202;

import java.util.HashSet;
import java.util.Set;

public class Solution {

    public static void main(String[] args) {
        isHappy(2);
    }
    public static boolean isHappy(int n) {
        Set<Integer> s = new HashSet<>();
        int m=n;
        while (m != 1){
            int temp=0;
            while (m  != 0){
                temp+= Math.pow(m%10,2);
                m/=10;
            }
            m=temp;
            if (s.contains(m) ) return false;
            else s.add(m);
        }
        return true;
    }
}
